package top.yuechenc.manage.common.token;

import com.alibaba.fastjson.JSON;
import springfox.documentation.spring.web.json.Json;

import java.util.HashMap;
import java.util.Map;

/**公用返回结果
 * @author Zhiwei Wang
 * @date 2020/2/17 19:53
 */
public class ShopResult {
    Object data;
    Map meta;

    /**封装的返回码及信息
     * @author Zhiwei Wang
     * @date 2020/2/17 19:53
     */
    public enum Metaa {
        NO_TOKEN(101,"无token，请登录后操作！"),
        NO_MANAGE(102,"用户不存在，请重新登录！"),
        OK(200, "请求成功"),
        CREATED(201, "创建成功"),
        CREATED_FAIL(202, "创建失败"),
        UPDATE(203, "修改成功"),
        UPDATE_FAIL(204, "修改失败"),
        DELETED(205, "删除成功"),
        DELETED_FAIL(206, "删除失败"),
        SELECT(207, "查询成功"),
        SELECT_FAIL(208, "查询失败"),
        BAD_REQUEST(400, "请求的地址不存在或者包含不支持的参数"),
        UNAUTHORIZED(401, "未授权"),
        FORBIDDEN(403, "被禁止访问"),
        NOT_FOUND(404, "请求的资源不存在"),
        INTERNAL_SERVER_ERROR(500, "内部错误");

        private Integer status;
        private String msg;

        public Integer getStatus() {
            return status;
        }

        public void setStatus(Integer status) {
            this.status = status;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        private Metaa(int status, String msg) {
            this.status = status;
            this.msg = msg;
        }
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Map getMeta() {
        return meta;
    }

    public void setMeta(Map meta) {
        this.meta = meta;
    }

    public ShopResult(){

    }

    public ShopResult(Integer status,String msg) {
        Map<String,Object> map = new HashMap<>();
        map.put("status", status);
        map.put("msg", msg);
        this.meta = map;
    }

    public ShopResult(Integer status,String msg,Object data) {
        Map<String,Object> map = new HashMap<>();
        map.put("status", status);
        map.put("msg", msg);
        this.meta = map;
        this.data=data;
    }

    public ShopResult(Metaa meta) {
        Map<String,Object> map = new HashMap<>();
        map.put("status", meta.status);
        map.put("msg", meta.msg);
        this.meta = map;
    }

    public ShopResult(Metaa meta,String msg) {
        Map<String,Object> map = new HashMap<>();
        map.put("status", meta.status);
        map.put("msg", meta.msg+"："+msg);
        this.meta = map;
    }

    public ShopResult(Metaa meta,Object data) {
        Map<String,Object> map = new HashMap<>();
        map.put("status", meta.status);
        map.put("msg", meta.msg);
        this.meta = map;
        this.data = data;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public static void main(String[] args) {
        StringBuilder a= new StringBuilder();
        for (ShopResult.Metaa metaa : ShopResult.Metaa.values()) {
            a.append("|").append(metaa.getStatus()).append("|").append(metaa.getMsg()).append("|\r\n");
        }
        System.out.print(a);
    }
}
